/**
 * 
 * Praktikum CG WP WS13/14
 * Gruppe: Andreas Rebri(andreas.rebri@haw-hamburg.de)
 * 		   Joschka Schulz(joschka.schulz@haw-hamburg.de)
 * Aufgabe : Aufgabenblatt 3
 * Verwendete Quellen: -
 */

package edu.cg1.exercises.marchingcubes;
/**
 * 
 * Praktikum CG WP WS13/14
 * Gruppe: Andreas Rebri(andreas.rebri@haw-hamburg.de)
 * 		   Joschka Schulz(joschka.schulz@haw-hamburg.de)
 * Aufgabe : Aufgabenblatt 2
 * Verwendete Quellen: -
 */


import java.util.Timer;

import javax.media.j3d.Group;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.universe.SimpleUniverse;

/**
 * �bernommen aus Aufgabe 1. Erstellt einen Scenengraphen, das Univerum und
 * eine Kugel.
 */
public class Aufgabe3 extends CG1Frame {
	/*
	 * Create the default scene graph.
	 */
	@Override
	protected void createSceneGraph() {
		// Set the view position back far enough so that we can see things
		TransformGroup viewTransform = universe.getViewingPlatform()
				.getViewPlatformTransform();
		Transform3D t3d = new Transform3D();
		t3d.lookAt(new Point3d(10, 10, 20), new Point3d(0, 0, 0), new Vector3d(
				0, 1, 0));
		t3d.invert();
		viewTransform.setTransform(t3d);

//		addLight(universe);
//		Sphere sphere = new Sphere(3);
//		MarchingCubes mc = new MarchingCubes();
//		Shape3D shape = mc.tesselateMarchingCubes(sphere);
//		AppearanceHelper.setColor(shape, new Color3f(0.2f, 0.1f, 0.6f));
//		scene.addChild(shape);
		
		addLight(universe);
		Torus torus = new Torus(3, 2);
		MarchingCubes mc = new MarchingCubes();
		Shape3D shape = mc.tesselateMarchingCubes(torus,-5,5,100);
		AppearanceHelper.setColor(shape, new Color3f(0.2f, 0.1f, 0.6f));
		scene.addChild(shape);
		
		// Assemble scene
		scene.compile();
		universe.addBranchGraph(scene);
	}

	/**
	 * Setup the lights in the scene. Attention: The light need to be added to
	 * the scene before the scene in compiled (see createSceneGraph()).
	 */
	private void addLight(SimpleUniverse universe) {
		addPointLight(new Point3f(0, 6, 0));
		addPointLight(new Point3f(6, 6, 0));
		addPointLight(new Point3f(0, 6, 6));
	}

	/**
	 * Program entry point.
	 */
	public static void main(String[] args) {
		// Create the central frame
		Aufgabe3 frame = new Aufgabe3();
		// Add content to the scene graph
		frame.createSceneGraph();
	}
}
